package game.classes;

import java.util.HashMap;
import javax.imageio.ImageIO;

/**
 * @author Chris
 */
public class SpriteFactory {

    private static SpriteFactory single = new SpriteFactory();
    private HashMap sprites = new HashMap();

    public static SpriteFactory get() {
        return single;
    }

    public Sprite getSprite(String ref) {
        if (sprites.get(ref) != null) {
            return (Sprite) sprites.get(ref);
        }

        Sprite sprite = null;

        try {
            java.net.URL longref = this.getClass().getClassLoader().getResource("game/sprites/" + ref);
            sprite = new Sprite(ImageIO.read(longref));
            sprites.put(ref, sprite);

        } catch (Exception e) {
            System.out.println("No se pudo cargar la imagen: " + ref);
            System.exit(0);
        }

        return sprite;
    }
}
